package com.dq.domain.record;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.org.Org;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @Author luchangtong
 * @Date 2019/11/20 15:03
 */
@Entity
@Data
@ApiModel("休息日记录")
public class RestDayRecord extends BaseEntity implements VO.ToVO {
    @ApiModelProperty(value = "门店",hidden = true)
    @ManyToOne
    protected Org org;
    @ApiModelProperty("开始时间")
    protected Long beginTime;
    @ApiModelProperty("结束时间")
    protected Long endTime;
    @ApiModelProperty("原因")
    protected String reason;

    public RestDayRecord() {

    }

    public RestDayRecord(Long beginTime, Long endTime, String reason, Org sysDept) {
        this.beginTime = beginTime;
        this.endTime = endTime;
        this.reason = reason;
        this.org = sysDept;
    }

    @Data
    @ApiModel(value = "休息日记录视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        protected Long id;

        @ApiModelProperty("开始日期")
        protected String beginTime;

        @ApiModelProperty("截止日期")
        protected String endTime;

        @ApiModelProperty("休息时间")
        protected String restReason;

        @ApiModelProperty(value = "创建时间")
        private String createTime;
        @ApiModelProperty(value = "修改时间")
        private String lastModifyTime;
        @ApiModelProperty(value = "创建者id")
        private Long createUserId;
        @ApiModelProperty(value = "创建者name")
        private String createUserName;
        @ApiModelProperty(value = "修改者id")
        private Long updateUserId;
        @ApiModelProperty(value = "修改者name")
        private String updateUserName;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.beginTime = fmt(this.getBeginTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.endTime = fmt(this.getEndTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.restReason = fmt(this.getReason());

        vo.createTime = TimeUtil.longToString(this.createTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.lastModifyTime = TimeUtil.longToString(this.lastModifyTime, TimeUtil.YYYY_MM_DD_HH_MM_SS);
        vo.createUserId = this.createUser == null ? null : this.createUser.getId();
        vo.createUserName = this.createUser == null ? null : this.createUser.getUsername();
        vo.updateUserId = this.updateUser == null ? null : this.updateUser.getId();
        vo.updateUserName = this.updateUser == null ? null : this.updateUser.getUsername();
        return vo;
    }
}
